import { RootState } from "@/store"
import {
  Store as VuexStore,
  CommitOptions,
  DispatchOptions,
  Module
} from "vuex"

import type { UserState } from "./state";
import { state } from "./state"
import type { Mutations } from "./mutations"
import { mutations } from "./mutations"
import type { Actions } from "./actions"
import { actions } from "./actions"

export { UserState }

export type UserStore<S = UserState> = Omit<VuexStore<S>, 'getters' | 'commit' | 'dispatch'>
  & {
    commit<K extends keyof Mutations, P extends Parameters<Mutations[K]>[1]>(
      key: K,
      payload: P,
      options?: CommitOptions
    ): ReturnType<Mutations[K]>
  } & {
    dispatch<K extends keyof Actions>(
      key: K,
      payload: Parameters<Actions[K]>[1],
      options?: DispatchOptions
    ): ReturnType<Actions[K]>
  };

export const store:Module<UserState,RootState> = {
  state,
  mutations,
  actions
}